<?php
namespace app\blog\model;
use think\Model;
use think\Db;

class StaffModel extends Model{
    //员工列表
    public function StaffList($keywordComplex){
        //查询登录id
        $adminid = cmf_get_current_admin_id();
        $where = array();
        if($adminid != 1){
             $where['a.id'] = $adminid;
        }
        //判断所属店铺
        $data = Db::name("user")->alias("a")->where($keywordComplex)
                ->where($where)
                ->join('__SHOP__ b','b.re_guid=a.shop_guid')
                ->field('a.*,b.shop_name,b.address')
                ->paginate(10);
        return $data;
    }
    //添加店铺员工数据
    public function StaffPostAdd($data){
        //查询登录id
        $adminid = cmf_get_current_admin_id();
        $shopguid = Db::name("user")->where("id=".$adminid)->find();//店铺唯一标识$dataa["shop_guid"]
        $log = array();
        $log["user_guid"] = guid();//唯一标识
        $log["shop_guid"] = $shopguid["shop_guid"];
        $log["user_nickname"] = $data["user_nickname"];
        $log["mobile"] = $data["mobile"];
        $log["user_pass"] = cmf_password($data["user_pass"]);
        $log["sex"] = $data["sex"];
        $log["user_type"] = 3;//店铺员工
        $log["create_time"] = time();
        $result = Db::name("user")->insert($log);
        return $result;
    }
    //修改员工信息，获取历史数据
    public function StaffHistory($m_guid){
        $result = Db::name("user")->where("user_guid",$m_guid)->find();
        return $result;
    }
    //修改员工信息数据提交
    public function StaffEditPost($data){
        $log = array();
        $log["user_nickname"] = $data["user_nickname"];
        $log["mobile"] = $data["mobile"];
        $log["user_pass"] = cmf_password($data["user_pass"]);
        $log["sex"] = $data["sex"];
        $result = Db::name("user")->where("user_guid",$data["m_guid"])->update($log);
        return $result;
    }
    //删除员工信息
    public function StaffDelete($m_guid){
        $result = Db::name("user")->where("user_guid",$m_guid)->delete();
        return $result;
    }
}